package com.hdphone.zljutils.impl;

import com.hdphone.zljutils.ZljUtils;
import com.hdphone.zljutils.inter.IDimenUtil;

/**
 * @author sq
 * @date 2020/10/19
 * @describe
 */
public class DimenUtilImpl implements IDimenUtil {
    @Override
    public int dip2px(float dpValue) {
        final float scale = ZljUtils.getApp().getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }

    @Override
    public int px2dip(float pxValue) {
        final float scale = ZljUtils.getApp().getResources().getDisplayMetrics().density;
        return (int) (pxValue / scale + 0.5f);
    }

    @Override
    public int sp2px(int spValue) {
        final float fontScale = ZljUtils.getApp().getResources().getDisplayMetrics().scaledDensity;
        return (int) (spValue * fontScale + 0.5f);
    }

}
